package com.example.kehu.controller;

import com.example.kehu.entity.Client;
import com.example.kehu.service.ClientService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.example.common.vo.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * --- 业精于勤,荒于嬉 ---
 *
 * @author Song
 * @date 2024/9/11
 * @desc First
 */
@RestController
@RequestMapping("/attract/client")
public class ClientController {

    @Resource
    private ClientService clientService;

    @GetMapping("/list")
    public R finaAll() {
        List<Client> list = clientService.finaAll();
        return R.ok(list);
    }


    // @GetMapping("/list")
    // public R findList(@RequestParam HashMap<String,String> map){
    //     int pageNum = Integer.parseInt(map.get("pageNum"));
    //     int pageSize = Integer.parseInt(map.get("pageSize"));
    //     PageHelper.startPage(pageNum,pageSize);
    //
    //     List<Client> list = clientService.findByMap(map);
    //     PageInfo<Client> info = new PageInfo<>(list);
    //     return R.ok(info);
    // }



    @GetMapping("/del")
    public R delById(int id){
        boolean isok = clientService.delete(id);
        return R.ok(isok);
    }

    @PostMapping("/add")
    public R addList(@RequestBody Client client) {
        boolean isOk = clientService.addList(client);
        return R.ok(isOk);
    }

}
